package com.coolgor.xutil.Common;

import java.sql.ResultSet;

public class DataTree {
	
	private DataTreeNode root ;
	private int numOfNode ;	
	
	public DataTree() { }
	
	public DataTree(ResultSet rs){}
	
	public DataTree(DataTreeNode root){
		this.root = root;
		this.numOfNode = root.getNumOfLeaf()+1;
	}
	
	
	public DataTreeNode getRoot() {
		return root;
	}

	public void setRoot(DataTreeNode root) {
		this.root = root;
	}

	public int getNumOfNode() {
		return numOfNode;
	}

	public void setNumOfNode(int numOfNode) {
		this.numOfNode = numOfNode;
	}

	
	public boolean createTree(ResultSet rs, String id, String pid){
		this.numOfNode = 0;		
		return true;
	}
	
	public void print() {
		printNode(this.getRoot());
	}
	private void printNode(DataTreeNode node) {
		System.out.print("|"); 
		for (int i=0; i<node.getLevel(); i++) System.out.print("--"); 
		System.out.print(">"); 
		System.out.print("【"+node.getLevel()+"】"); 
		System.out.println(node.getObject().toString());
		if (!node.isLeaf()) {
			for (int j=0; j<node.getChildren().size(); j++) {
				printNode(node.getChild(j));
			}
		}
	}
}